package cc.flybb.sharedpreferences2;

import android.content.Context;
import android.content.SharedPreferences;

public class MyData {

    public int number;

    private Context context;

    //Alt + Ins
    public MyData(Context context) {
        this.context = context;
    }

    public void save(){
        String name = context.getResources().getString(R.string.MY_DATA);
        SharedPreferences shp = context.getSharedPreferences(name,Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = shp.edit();
        String key = context.getResources().getString(R.string.MY_KEY);
        editor.putInt(key,number);
        editor.commit();
    }
    public int load(){
        String name = context.getResources().getString(R.string.MY_DATA);
        SharedPreferences shp = context.getSharedPreferences(name,Context.MODE_PRIVATE);
        String key = context.getResources().getString(R.string.MY_KEY);
        //int x = shp.getInt(key,0);
        int x = shp.getInt(key,context.getResources().getInteger(R.integer.deValue));
        number = x;
        return x;
    }
}
